home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_075 / hardcopy / hardcopy.doc < prev    next >
Text File  |  1992-05-06  |  13KB  |  277 lines

  1. OVERVIEW:
  2.  
  3. HARDCOPY is a program that "clones" the CLI output stream and sends it to two
  4. places at one time:  the normal CLI window, and a file.  With it, you can
  5. create a hardcopy listing of all the activity that went on in a CLI window. 
  6. This can be useful for documentation purposes, error analysis, and error
  7. reporting.  The advantage of using HARDCOPY instead of output-redirection is
  8. that you still see the output in the CLI window (as well as capture it in a 
  9. file).  This makes getting a hardcopy listing of an interactive session much 
  10. easier.  HARDCOPY's major drawback is that it only copies text that goes to 
  11. or from the CLI window; it does not record any of the activity that occurs in 
  12. programs that open their own Intuition windows.  It will, however, record all 
  13. data entered in CON and RAW windows opened from the CLI window from which a
  14. HARDCOPY is being made.
  15.  
  16.  
  17. USING HARDCOPY:
  18.  
  19. To use HARDCOPY, type:
  20.  
  21.     1> HARCOPY TO <file>
  22.  
  23. where <file> is the name of a file where HARDCOPY will record your CLI
  24. session.  This can be on disk, in RAM:, or even directly to PRT:.  Note that
  25. HARDCOPY will be writing to this file every time something happens in your CLI
  26. window, so if you are HARDCOPYing to disk, make sure you select a disk that
  27. can stay in a disk drive!
  28.  
  29. HARDCOPY will try to start up a new process that will monitor your CLI and
  30. copy its output to the file you have selected.  In order to start the
  31. monitoring process, HARDCOPY uses the Execute() function.  This function
  32. requires the RUN command to be in the C: directory.  If your workbench disk is
  33. not in a drive, you will get a disk-insert requester, so don't be alarmed.
  34.  
  35. Once the monitoring process is started, HARDCOPY waits for it to signal that
  36. it is ready to begin copying to the file (you will receive a message informing 
  37. you of this).  In a few seconds, you should get another message that says the
  38. hardcopy session is beginning.  
  39.  
  40. If you get an error message (like "Unknown command HARDCOPY"), or if HARDCOPY 
  41. seems to hang (it does not return to the CLI prompt), then follow the 
  42. instructions under ERROR RECOVERY.
  43.  
  44. Once the HARDCOPY monitor process is under way, you should be returned to the
  45. CLI prompt.  At this point you can enter commands normally.  All the input
  46. from and output to the CLI window (or any CON or RAW window opened from the
  47. CLI) will be routed to the file as well as the CLI window.
  48.  
  49. When you want to stop sending HARDCOPY output to the file, issue the command
  50.  
  51.     1> HARDCOPY END
  52.  
  53. This will signal the monitor process to close the file and stop running.  You
  54. should receive a message informing you that the HARDCOPY transcript is
  55. complete.  At this point, you can use the output file in whatever way you
  56. choose.
  57.  
  58.  
  59. USAGE NOTES:
  60.  
  61. To avoid disk swapping due to the HARDCOPY process, make sure the HARDCOPY
  62. output file is on a disk that will remain in one of the disk drives.  RAM: is
  63. good for small HARDCOPY sessions, but it can fill up faster than you think!
  64.  
  65. Don't HARDCOPY TO *.  When anything appears in your CLI window, HARDCOPY will
  66. try to write it to the output file.  Since the output file is your CLI,
  67. HARDCOPY will see its own output as something that must be copied.  This will
  68. cause am infinite loop, or a deadlock situation, depending on when the output
  69. occurs.
  70.  
  71. Don't ENDCLI without first ending your HARDCOPY session.  If you do, the CLI
  72. window won't close (since HARDCOPY is still using it), but you will not be 
  73. able to enter any more commands.  See the ERROR RECOVERY section for 
  74. information on what to do if this occurs.
  75.  
  76. HARDCOPY uses the Execute() call, which requires the RUN command to be in the C:
  77. directory.  HARDCOPY executes the HARDCOPY command, so the HARDCOPY command
  78. itself must be in the current directory, or in the current PATH searched by
  79. the Execute() call.
  80.  
  81. You can not TYPE, EDIT, or otherwise look at or change the HARDCOPY output file
  82. until after you issue the HARDCOPY END command.
  83.  
  84. You can not have more than one HARDCOPY session going to the same file.
  85.  
  86. HARDCOPY creates a new version of the file each time it is invoked, so it will
  87. destroy the current version of the specified output file, if one already exists.
  88.  
  89.  
  90. ERROR RECOVERY:
  91.  
  92. There are two kinds of errors that can occur:  HARDCOPY may fail to start the
  93. monitoring process, or something may happen to your CLI so that you need to end
  94. the HARDCOPY monitor "by hand".
  95.  
  96. When you start HARDCOPY, it spawns a new process to do the monitoring for
  97. you.  HARDCOPY waits to make sure that this process is running and ready to
  98. record your output before it lets you enter more commands (it informs you of
  99. this with a "waiting" message).  
  100.  
  101. If an error message appears while HARDCOPY is waiting, or if HARDCOPY never 
  102. completes (you don't get the CLI prompt back), then you should wait till all
  103. the disk activity (if any) stops, and then press CTRL-E.  This will stop 
  104. HARDCOPY from waiting for the monitor process to start up (this may leave a
  105. monitor process active).
  106.  
  107. Use the STATUS command to check that there is no HARDCOPY monitor process 
  108. running.  If there is, try typing HARDCOPY END.  If that does not work, then 
  109. use the BREAK command to send a CTRL-C and then a CTRL-E to the HARDCOPY 
  110. monitor process (see the example below).
  111.  
  112. If something happens to your CLI so that you can not enter the HARDCOPY END
  113. command (for instance, you type ENDCLI while there is a HARDCOPY session in
  114. progress), then you can stop HARDCOPY from another CLI.  Use the STATUS
  115. command to find the process number of the HARDCOPY monitor.  Then use BREAK to
  116. send it a CTRL-C.  If the monitored CLI is still active, make sure some input
  117. or output occurs to the window (unfortunately, type-ahead does not qualify as
  118. input).  Once you have done this (or if it is not possible), then use BREAK 
  119. again to send a CTRL-E to the HARDCOPY process.  Use STATUS to verify that the 
  120. process really is gone.
  121.  
  122. For example, suppose you have two CLIs running (1 and 2), and had a HARDCOPY 
  123. session in progress for CLI number 2, but forgot about it and typed ENDCLI
  124. without having ended the HARDCOPY session.  You should do the following (from
  125. CLI number 1):
  126.  
  127.     1> STATUS                                    ; see what processes there are
  128.     Task  1: Loaded as command: STATUS           ; this CLI
  129.     Task  4: Loaded as command: HARDCOPY         ; HARDCOPY monitor process
  130.  
  131.     1> BREAK 4 ALL                               ; send it a CTRL-C and CTRL-E
  132.  
  133.     1> STATUS                                    ; check what we've done
  134.     Task  1: Loaded as command: STATUS
  135.     1>                                           ; monitor is gone!
  136.  
  137. Now suppose you have two CLIs running (1 and 2), and had a HARDCOPY session in
  138. progress for CLI number 2, but ran a program that entered an infinite loop, so
  139. you can not end the HARDCOPY session by typing HARDCOPY END.  You should do 
  140. the following (from CLI number 1):
  141.  
  142.     1> STATUS                                    ; see what processes there are
  143.     Task  1: Loaded as command: STATUS           ; this CLI
  144.     Task  2: Loaded as command: LoopForEver      ; CLI 2 in an infinite loop
  145.     Task  4: Loaded as command: HARDCOPY         ; HARDCOPY monitor process
  146.  
  147.     1> BREAK 4 C                                 ; send monitor a CTRL-C
  148.     ; click in CLI window 2, and force some I/O to occur;
  149.     ; click back in CLI window 1;
  150.  
  151.     1> STATUS                                    ; check what we've done
  152.     Task  1: Loaded as command: STATUS
  153.     Task  2: Loaded as command: LoopForEver      ; nothing we can do about this
  154.     1>                                           ; but monitor is gone!
  155.  
  156.  
  157. USES FOR HARDCOPY:
  158.  
  159. I see HARDCOPY as a useful method of documenting CLI functions.  For instance, 
  160. it can be used to make a transcript of what people have to do to start up your
  161. program or customize their environment to make your program more useful, or
  162. what they have to do the move your program to a hard disk, etc.
  163.  
  164. HARDCOPY can be used to make an error log during compilation of programs when
  165. you want to see the errors AND record them in a file (where you can use an
  166. editor to look at the error log at the same time as the source code).
  167.  
  168. If you are running a program that sets up its own screen and eventually
  169. crashes, you can have it use printf() to send diagnostic messages to the CLI
  170. window, and have them recorded to a file even if the program crashes before
  171. you can flip the screen to look at the CLI window.
  172.  
  173. You can use HARDCOPY to capture the exact input you used to produce an error,
  174. so that you can report the error easier (and so people will believe that it
  175. really occured).
  176.  
  177. You can HARDCOPY TO PRT: to produce a printed listing of your work as it
  178. happens.  
  179.  
  180. HARDCOPY can be used to have your CLI session show up in two CON windows
  181. simultaneously.  (Pretty useless, but it looks neat!  Use
  182.  
  183.     1> HARDCOPY TO CON:0/0/640/100/Hardcopy
  184.  
  185. to see what I mean.)
  186.  
  187. I expect there are other uses, but I can't think of them.  I wrote it mostly
  188. as an exercise, and because I've always wanted to be able to do this on a VAX
  189. running VMS, but never could.  If you come up with interesting uses, please 
  190. let me know.
  191.  
  192.  
  193. TECHNICAL NOTES:
  194.  
  195. HARDCOPY is based on MONPROC by Phillip Lindsay of Commodore-Amiga, and is an
  196. example of a real-life program that uses his method to monitor the AmigaDOS
  197. activity of a process.  It was the simplest and most useful example I could
  198. think of, but undoubtedly there are others.
  199.  
  200. Phillip pointed out that the pr_PktWait field of the Process structure is used
  201. for an alternate taskwait() routine.  AmigaDOS calls this routine whenever a
  202. process is waiting for AmigaDOS messages to be issued or returned.  HARDCOPY
  203. installs its own code in this field.  This code waits for AmigaDOS packets to
  204. arrive, and then signals a monitoring process.  This process checks to see if
  205. the packet is to or from the CLI window.  If it is, it writes the contents of
  206. the packet's data buffer to the output file.  Then it signals the pr_PktWait
  207. routine that it is through writing (via a semaphore).  At that point, the
  208. packet wait routine returns the packet to the process for its own use.
  209.  
  210. HARDCOPY assumes that all READ and WRITE packets with dp_Arg1 fields equal to
  211. zero are CLI I/O packets.  This assumption probably is wrong, but it holds in
  212. enough cases to make this program useful.  If someone finds cases where this
  213. fails, please let me know.
  214.  
  215. The HARDCOPY TO <file> command simply sets up the monitoring process and
  216. passes it a pointer to the process to be monitored (via an undocumented 
  217. command-line argument).  The monitor process signals HARDCOPY TO that it is
  218. ready via a CTRL-C (HARDCOPY TO is waiting for either the CTRL-C from the
  219. monitor or a CTRL-E from the user).
  220.  
  221. The monitor process runs as a separate process, but the CLI process executes
  222. the pr_PktWait routine, which shares data with the HARDCOPY monitor process,
  223. including the signal and semaphore used to coordinate the activity of the
  224. packet wait routine and the HARDCOPY process.  This gets to be somewhat
  225. confusing when you look at the code, so try to remember that the PacketWait()
  226. routine (and the StartHardCopy() and EndHardCopy() routines) run in the
  227. monitored CLI process, while the rest of the program runs in the monitoring
  228. HARDCOPY process, asynchronously.
  229.  
  230. When the user wants to end the hardcopy session, he runs HARDCOPY END, which
  231. sends a CTRL-C to the monitor (the monitor stores a pointer to itself in the
  232. tc_UserData field of the monitored CLI task; HARDCOPY END looks here for the 
  233. address of the task to signal).
  234.  
  235. When the monitor process receives the CTRL-C, it de-installs the pr_PktWait
  236. code.  At this point, since HARDCOPY END is running in the CLI window, and
  237. since it is not performing a taskwait(), it is safe to remove the pr_PktWait
  238. code (that is, the CLI process is not currently running it).  Just to be sure,
  239. however, the monitor waits for a CTRL-E.  HARDCOPY END writes a message that
  240. the session is complete (ensuring that pr_PktWait is not in use anymore), and
  241. signals the CTRL-E to the monitor process.  
  242.  
  243. The extra CTRL-E is there mainly so that you can stop HARDCOPY monitors 
  244. "by hand" using the BREAK command.  The time between the BREAK C and BREAK E
  245. commands is used to make sure some I/O takes place in the monitored CLI
  246. window.  This ensures that the monitored process is no longer waiting in the
  247. PacketWait() routine when HARDCOPY receives the CTRL-E and its code is removed
  248. from memory.
  249.  
  250.  
  251. HOW TO COMPILE AND LINK HARDCOPY:
  252.  
  253. HARDCOPY was developed using the Lattice C Compiler version 3.10.  Phillip
  254. Lindsay's code was originally designed for the Manx Aztec C compiler, and I
  255. have tried to keep it as compatable as possible.  I do not own the Manx
  256. compiler, however, so I don't know that it still works with it.  I suspect
  257. that it will need nothing more than minor adjustments.
  258.  
  259. To compile and link with Lattice, use the command:
  260.  
  261.     1> LC -v -L HARDCOPY
  262.  
  263. The -v suppresses stack overflow checking.  THIS IS CRITICAL!  HARDCOPY will
  264. fail if it is not compiled in this fashion.  I do not believe that Manx has
  265. overflow checking.  
  266.  
  267. The executable should be placed in the C: directory.
  268.  
  269.  
  270. AUTHOR:
  271.  
  272. Davide P. Cervone                                   DPVC@UORDBV.BITNET
  273. University of Rochester Computing Center            dpvc@tut.cc.rochester.EDU
  274. Taylor Hall                                         dpvc@ur-tut.UUCP
  275. Rochester New York  14627
  276. (716) 275-2811
  277.